<?php
class Administrator extends CI_Controller {
	
	    function __construct()
       {
            parent::__construct();
		$this->load->helper("html");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->model("bc_model");
		$this->load->model("administrator_model");
		$this->load->helper(array('form', 'url'));
		$this->load->database();
		//$this->load->library('session');
	}
	function index()
	{

	$data['title']="Administrator Log in";
		$data["admin_data"] = $this->administrator_model->administrator_login();
		//$data["guest_comment_data"] = $this->admin_model->admin_all_comment();
		$this->load->view('administrator_view',$data);
	}
	function process_login()
	{
		$this->load->database();
		if(isset($_POST['cmdlogin']))
		{
			$UserName = $_POST['txtUserName'];

			$Password = $_POST['txtPassword'];

			$query = $this->db->query("select * from users where UserName='$UserName' and Password='$Password'");

			if($query->num_rows()==1)

			{	
				$row = $query->row(); 
				$a_code = $row->a_code;
				if($row->type=='admin') 
				{	
					$baseurl= base_url();
					$admin="admin";
					session_start();
					$_SESSION['administrator_log']=$row->a_code;
					//echo $_SESSION['administrator_log'];
					header("location: $baseurl$admin");
					//$session_id = $this->session->userdata('session_id');
					$this->session->set_userdata('administrator_log', $a_code);
					$administrator_log = $this->session->userdata('administrator_log');
					//echo $a;
					//$_SESSION['administrator_log']=$row->a_code;
					$this->session->keep_flashdata('administrator_log');
					$data["administrator_log"] = $administrator_log;		
					$data["news_envents_data"] = $this->admin_model->admin_all_news();
					//$data["guest_comment_data"] = $this->admin_model->admin_all_comment();
					$this->load->view('admin_view',$data);
					
				}
				else if
				($row->type=='superadmin')
				{
					$baseurl= base_url();
					$loads="loads";
					session_start();
					$_SESSION['administrator_log']=$row->a_code;
					//echo $_SESSION['administrator_log'];
					header("location: $baseurl$loads");
					
				}
				else
				{
					$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/error.gif' /></td><td>YOUR FORBIDDEN TO ENTER THIS PAGE</td></tr></table>";	
				}
			}
			else
			{
				$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/error.gif' /></td><td>INVALID USER</td></tr></table>";
			}
		}
			$data['title']="Administrator Log in";
			$data["admin_data"] = $this->administrator_model->administrator_login();
			//$data["guest_comment_data"] = $this->admin_model->admin_all_comment();
			$this->load->view('administrator_view',$data);
	}
}
?>